package com.wlz.heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wlz
 * @date 2022-07-09  4:35 下午
 */
@Slf4j
public class MyHeartBeatNettyClientHandler extends SimpleChannelInboundHandler<String> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exception {
        log.info(" 【客户端】 接收到的消息: {}", s);
        if (s != null && s.equals("idle close ...")) {
            log.info(" 服务端关闭连接，客户端也关闭... ");
            ctx.channel().close();
        }
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
